﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
public partial class Personal : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String user = Session["username"].ToString();
        String sex = "未知";
        String age = "未知";
        String mainteam = "未知";
        String email = "未知";
        String phone = "未知";

        String connString = "server=localhost;database=test;uid=root;pwd=123456";
        MySqlConnection conn = new MySqlConnection(connString);
        conn.Open();

        String sqlselect = "select * from test.webuser where username = '" + user + "';";
        MySqlCommand mycommand = new MySqlCommand(sqlselect, conn);
        MySqlDataReader mdr = mycommand.ExecuteReader();
        if (mdr.Read())
        {
            sex = mdr["sex"].ToString();
            age = mdr["age"].ToString();
            mainteam = mdr["mainteam"].ToString();
            email = mdr["email"].ToString();
            phone = mdr["phone"].ToString();
            conn.Close();
        }
        if (!IsPostBack)
        { 
        TextBox1.Text = user;
        TextBox2.Text = sex;
        TextBox3.Text = age;
        TextBox4.Text = mainteam;
        TextBox5.Text = email;
        TextBox6.Text = phone;
        }
        
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        String user = Session["username"].ToString();
        String sex = TextBox2.Text;
        String age = TextBox3.Text;
        String mainteam = TextBox4.Text;
        String email = TextBox5.Text;
        String phone = TextBox6.Text;


        String connString = "server=localhost;database=test;uid=root;pwd=123456";
        MySqlConnection conn = new MySqlConnection(connString);
        conn.Open();
        String sqlselect = "select * from test.webuser where username = '" + user + "';";
        MySqlCommand mycommand = new MySqlCommand(sqlselect, conn);
        MySqlDataReader mdr = mycommand.ExecuteReader();
        if (mdr.Read())
        {
            conn.Close();
            conn.Open();
            String sql = "update webuser set sex='" + sex + "',age='" + age + "',mainteam='" + mainteam + "',email='" + email + "',phone='" + phone + "' where username = '" + user + "';";// 
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            Response.Write("<script>alert('更改成功主队是:" + mainteam + "');window.location='http://localhost:50015/index.aspx';</script>");
        }
        else
        {
            Response.Write("<script>alert('没这个人')</script>");
        }
        conn.Close();
        
    }
}